//----------商品详情的js效果-------------------

function Xiangqing(box){
	this.oBox=box;
	this.oDt=$(".box",this.oBox)[0];
	this.oDd=$(".littleimg",this.oBox)[0];
	this.oScreen=$(".screen",this.oDt)[0];
	this.Bimg=$("img",this.oDt)[1];
	this.Simg=$("img",this.oDd);
	this.num=$("#num-goods");
	this.reduce=$(".reduce",this.oBox)[0];
	this.add=$(".add",this.oBox)[0];
	this.see=$("#see");
	this.seeimg=$("img",this.see)[0];
	this.Big=$("#Big");
	this.SeeImg=$("img",this.Big)[0];
	this.addto=$("#addto");
	this.code=$("#goods-code").innerHTML.substring(5);
	var _this=this;
	this.addto.onclick=function(){
		_this.tianjia()
	}
	this.add.onclick=function(){
		var a=Number(_this.num.innerHTML);
		a++;
		_this.num.innerHTML=a;
	}
	this.reduce.onclick=function(){
		var a=Number(_this.num.innerHTML);
		if(a>1){
			a--;
		}
		_this.num.innerHTML=a;
	}
	for(var i=0;i<this.Simg.length;i++){
		this.Simg[i].onclick=function(){
			_this.Bimg.src=this.src;
			_this.seeimg.src=this.src;
			_this.SeeImg.src=this.src;
		}
	}
	this.oScreen.onmouseover=function(){
		_this.over();
	}
	this.oScreen.onmouseout=function(){
		_this.out();
	}
	document.onmousemove=function(ev){
		var e=ev||event;
		_this.move(e);
	}
	

}
Xiangqing.prototype.tianjia=function(){
	var n=Number(this.num.innerHTML);
	console.log(n)
	for(var i=0;i<n;i++){
		togouwu(this.code)
	}
	actionTip("您选择的商品已添加进购物车！");
}
Xiangqing.prototype.move=function(e){
	this.see.style.left=e.clientX-50-this.oScreen.offsetLeft+"px";
	this.see.style.top=e.clientY-50-this.oScreen.offsetTop+"px";
	if(this.see.offsetLeft>this.oScreen.offsetWidth-this.see.offsetWidth){
		this.see.style.left=this.oScreen.offsetWidth-this.see.offsetWidth+"px";
	}
	if(this.see.offsetLeft<0){
		this.see.style.left=0;
	}
	if(this.see.offsetTop<0){
		this.see.style.top=0;
	}
	if(this.see.offsetTop>this.oScreen.offsetHeight-this.see.offsetHeight){
		this.see.style.top=this.oScreen.offsetHeight-this.see.offsetHeight+"px";
	}
	var disx=this.see.offsetLeft;
	var disy=this.see.offsetTop;
	this.seeimg.style.left=-disx+"px";
	this.seeimg.style.top=-disy+"px";
	this.SeeImg.style.left=-2*disx+"px";
	this.SeeImg.style.top=-2*disy+"px";
	
}
Xiangqing.prototype.over=function(){
	this.see.style.display="block";
	this.Big.style.display="block";
	startMove(8,this.Bimg,{opacity:30});
	startMove(20,this.Big,{width:200,height:200,left:400,top:0});
}
Xiangqing.prototype.out=function(){
	this.see.style.display="none";
	startMove(8,this.Bimg,{opacity:100});
	startMove(10,this.Big,{width:0,height:0,left:140,top:182},function(){
		_this.Big.style.display="none";
	});
}



window.onload=function(){
	Testsign();//检测登录状态
	actionSerach();//搜索框效果
	actionBrandSeries();//左侧导航效果
	actionKefu();//右侧客服电话效果
	actionScroll();//右侧回到顶部效果
	var Box=$(".looktop")[0];
	var a=new Xiangqing(Box);
	var navt=$(".l-top")[0];
	var navb=$(".l-bottom")[0];
	var aLi=$("li",navt);
	var aLi1=$("li",navb);
	for(var i=0;i<aLi.length;i++){
		aLi[i].index=i;
		aLi[i].onmouseover=function(){
			for(var i=0;i<aLi.length;i++){
				aLi[i].style.background="#e1e1e1";
				aLi1[i].style.display="none";
				this.style.color="#666";
			}
			aLi1[this.index].style.display="block";
			this.style.background="#b2b2b2";
			this.style.color="#fff";
			if(this.index==0){
				for(var i=0;i<aLi.length;i++){
					aLi1[i].style.display="block";
				}
			}
		}
	}
}
